
<div class="span12">
    <div class="box box-color box-bordered">
        <div class="box-title">
            <h3>
                <i class="icon-table"></i>
                Notas
            </h3>
            <div class="actions">
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_ORDER'))) { ?>
                    <a href="#mdlOrder" role="button" class="btn" data-toggle="modal"><i class="icon-table"></i></a>
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_FILTER'))) { ?>
                    <!--a href="#mdlFilter" role="button" class="btn" data-toggle="modal"><i class="icon-search"></i></a-->
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_EXCEL'))) { ?>
                    <a href="<?php echo url_for('/notes/excelNotes'); ?>" role="button" class="btn" ><i class="icon-download-alt"></i></a>
                <?php } ?>

            </div>
        </div>
        <div class="box-content nopadding">

            <?php
            //echo $userOrderCount;die();

            if ($userOrderCount != 0) {
                ?>
                <table class="table table-bordered dataTable dataTable-scroll-x">
                    <thead>
                        <tr>
                            <?php foreach ($userTableOrder as $value) { ?>


                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 66 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Fecha</th><?php } ?>
                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 67 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Cadena</th><?php } ?>
                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 68 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Local</th><?php } ?>
                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 69 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Comentario</th><?php } ?>
                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 70 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Autor</th><?php } ?>
                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 71 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Categoría</th><?php } ?>
                                <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 72 && $value['UserTableOrder'][0]['visible'] == 1) { ?><th>Estado</th><?php } ?>


                            <?php } ?>
                        </tr>
                    </thead>
                    <tbody>

                        <?php
                        $dataArray = array();
                        $i = 0;
                        foreach ($notes as $value) {

                            $dataArray[$i][]['fecha'] = $value['note_date'];
                            $dataArray[$i][]['cadena'] = $value['Stores']['Formats']['name'];
                            $dataArray[$i][]['local'] = $value['Stores']['name'];
                            $dataArray[$i][]['comentario'] = $value['coments'];
                            $dataArray[$i][]['autor'] = $value['Users']['name'];
                            $dataArray[$i][]['categoria'] = $value['CategoryNote']['name'];
                            $dataArray[$i][]['estado'] = $value['active'];
                            $dataArray[$i][]['id_note'] = $value['id_note'];
                            $i++;
                        }


                        for ($x = 0; $x < $i; $x++) {
                            ?>
                            <tr>

                                <?php foreach ($userTableOrder as $value) { ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 66 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td><?php echo $dataArray[$x][0]['fecha']; ?></td><?php } ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 67 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td><?php echo $dataArray[$x][1]['cadena']; ?></td><?php } ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 68 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td><?php echo $dataArray[$x][2]['local']; ?></td><?php } ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 69 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td><?php echo $dataArray[$x][3]['comentario']; ?></td><?php } ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 70 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td><?php echo $dataArray[$x][4]['autor']; ?></td><?php } ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 71 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td><?php echo $dataArray[$x][5]['categoria']; ?></td><?php } ?>
                                    <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 72 && $value['UserTableOrder'][0]['visible'] == 1) { ?><td>
                                            <a href="#" >
                                                <button class="btn btn-<?php echo ($dataArray[$x][6]['estado']) ? 'danger' : 'success'; ?>" onclick="NotesActive(<?php echo $dataArray[$x][7]['id_note']; ?>,<?php echo $dataArray[$x][6]['estado']; ?>);">
                                                    <i class="icon-thumbs-<?php echo ($dataArray[$x][6]['estado']) ? 'down' : 'up'; ?>"></i>
                                                </button>
                                            </a>
                                        </td><?php } ?>
                                <?php }
                                ?>
                            </tr>
                            <?php
                        }
                        ?>

                    </tbody>
                </table>

            <?php } else { ?>  

                <table class="table table-bordered dataTable dataTable-scroll-x">
                    <thead>
                        <tr>
                            <th>Fecha</th>
                            <th>Cadena</th>
                            <th>Local</th>
                            <th style="width: 30%">Comentario</th>
                            <th>Autor</th>
                            <th>Categoria</th>
                            <th>Estado</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php foreach ($notes as $value) { ?>

                            <tr>
                                <td><?php echo $value['note_date']; ?></td>
                                <td><?php echo $value['Stores']['Formats']['name']; ?></td>
                                <td><?php echo $value['Stores']['name']; ?></td>
                                <td><?php echo nl2br($value['coments']); ?></td>
                                <td><?php echo $value['Users']['name']; ?></td>
                                <td><?php echo $value['CategoryNote']['name']; ?></td>
                                <td>
                                    <a href="#" >
                                        <button class="btn btn-<?php echo ($value['active']) ? 'danger' : 'success'; ?>" onclick="NotesActive(<?php echo $value['id_note']; ?>,<?php echo $value['active']; ?>,<?php echo $value['id_store']; ?>);">
                                            <i class="icon-thumbs-<?php echo ($value['active']) ? 'down' : 'up'; ?>"></i>
                                        </button>
                                    </a>
                                </td>
                            </tr>
                        <?php } ?>

                    </tbody>
                </table>


            <?php } ?>
        </div>
    </div>
</div>